const Redis = require('ioredis');
const redisConfig = require('../../../config/redis.json');
let client;

async function getRedisClient () {
    if (!client) {
        client = new Redis({
            host: redisConfig.host,
            keepAlive: redisConfig.keepalive,
            lazyConnect: true,
            password: redisConfig.password,
            port: redisConfig.port
        });
        await client.connect();
    }
    return client;
}

module.exports = {
    getRedisClient
};
